// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import GameData_red_blue_man from "./GameData_red_blue_man";
import Music, {musicName} from "../PublicScript/Music";
import PowerControl from "../PublicScript/PowerControl";
import ControlScript from "../PublicScript/ControlScript";
import FlyPower from "./FlyPower";
import HeroControl from "./HeroControl";

const {ccclass, property} = cc._decorator;

@ccclass
export default class BtnControl extends cc.Component {


    isGameAnim = false;
    onClick(e,d){
        if(this.isGameAnim){
            return;
        }
        console.log(e);
        let index = parseInt(d);
        Music.GamePlayEffect(musicName.click);
        //下一关
        if(index == 1){
            GameData_red_blue_man.nextGame(1);
        }
        //主页
        if(index == 2){
            cc.director.loadScene("Welcome");
        }
        //重来
        if(index == 3){
            PowerControl.reducePower(()=>{
                this.isGameAnim = true;
                HeroControl.manSkinName = null;
                let pos1 = cc.find("Canvas/power").children[0].children[0].convertToWorldSpaceAR(cc.v2(0,0));
                let pos2 = e.currentTarget.convertToWorldSpaceAR(cc.v2(0,0));
                ControlScript.instantiate("flyPower",(res)=>{
                    res.getComponent(FlyPower).init(pos1, pos2, ()=>{
                        cc.director.loadScene("GameScene");
                        this.isGameAnim = false;
                    })
                })
            })
        }
        //跳过
        if(index == 4){
            //todo 视频
            GameData_red_blue_man.showVideo({callback: ()=>{
                    GameData_red_blue_man.nextGame(1);
                }, name: "设置界面跳关"})
        }
        //删除
        if(index == 5){
            this.node.destroy();
        }
    }

}
